package top.continew.admin.controller.business;

import cn.shengchao.examstar.rpc.base.PageResult;
import cn.shengchao.examstar.rpc.orders.api.IOrderRpc;
import cn.shengchao.examstar.rpc.orders.req.OrderQueryPage;
import cn.shengchao.examstar.rpc.orders.req.Refund;
import cn.shengchao.examstar.rpc.orders.req.RefundQueryPage;
import cn.shengchao.examstar.rpc.orders.req.RemarkReq;
import cn.shengchao.examstar.rpc.orders.res.OrderInfo;
import cn.shengchao.examstar.rpc.orders.res.OrderList;
import cn.shengchao.examstar.rpc.orders.res.RefundList;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.common.context.UserContextHolder;

@Tag(name = "订单 API")
@RestController
@RequestMapping("/orders")
public class OrderController {
    @DubboReference
    private IOrderRpc orderRpc;

    @GetMapping
    @Operation(summary = "获取订单列表", description = "获取订单列表")
    public PageResult<OrderList> getOrderList(OrderQueryPage orderQueryPage) throws Exception {
        return orderRpc.getOrderList(orderQueryPage);
    }

    @GetMapping("{orderId}")
    @Operation(summary = "获取订单详情", description = "获取订单详情")
    public OrderInfo getOrderInfo(@PathVariable String orderId) throws Exception {
        return orderRpc.getOrderInfo(orderId);
    }

    @PostMapping("{orderId}/remarks")
    @Operation(summary = "订单备注", description = "订单备注")
    public void saveOrderRemarks(@PathVariable Long orderId, @RequestBody RemarkReq remarkReq) throws Exception {
        remarkReq.setUserId(UserContextHolder.getUserId());
        remarkReq.setOrderId(orderId);
        orderRpc.remarks(remarkReq);
    }

    @PutMapping("{orderId}/refund")
    @Operation(summary = "订单退款", description = "订单退款")
    public void refund(@RequestBody Refund refund) throws Exception {
        refund.setUserId(UserContextHolder.getUserId());
        orderRpc.refunds(refund);
    }

    @GetMapping("/refund")
    @Operation(summary = "订单退费列表", description = "订单退费列表")
    public PageResult<RefundList> getRefund(RefundQueryPage refundQueryPage) throws Exception {
        return orderRpc.getOrderRefund(refundQueryPage);
    }

}
